package com.feisuanyz.lyweb01.controller;

import com.feisuanyz.lyweb01.constant.ResultCodeConstant;
import com.feisuanyz.lyweb01.pojo.domain.SolutionDO;
import com.feisuanyz.lyweb01.pojo.dto.CreateGroup;
import com.feisuanyz.lyweb01.pojo.dto.DeleteGroup;
import com.feisuanyz.lyweb01.pojo.dto.RestResult;
import com.feisuanyz.lyweb01.pojo.dto.SolutionDTO;
import com.feisuanyz.lyweb01.pojo.dto.UpdateGroup;
import com.feisuanyz.lyweb01.pojo.query.QueryGroup;
import com.feisuanyz.lyweb01.pojo.query.SolutionQuery;
import com.feisuanyz.lyweb01.pojo.vo.PageResult;
import com.feisuanyz.lyweb01.service.SolutionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 解决方案
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Tag(name = "解决方案")
@RequestMapping("solution")
@RestController
public class SolutionController {

    @Autowired
    private SolutionService solutionService;

    /**
     * 获取解决方案列表
     *
     * @param query 解决方案查询对象
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Operation(summary = "获取解决方案列表")
    public RestResult<PageResult<SolutionDO>> getSolutionList(@Validated(QueryGroup.class) SolutionQuery query) {
        PageResult<SolutionDO> result = solutionService.getSolutionList(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取解决方案详情
     *
     * @param query 解决方案查询对象
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @Operation(summary = "获取解决方案详情")
    public RestResult<SolutionDO> getSolutionDetail(@Validated(QueryGroup.class) SolutionQuery query) {
        SolutionDO result = solutionService.getSolutionDetail(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 搜索解决方案
     *
     * @param query 解决方案查询对象
     * @return
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @Operation(summary = "搜索解决方案")
    public RestResult<PageResult<SolutionDO>> searchSolutions(@Validated(QueryGroup.class) SolutionQuery query) {
        PageResult<SolutionDO> result = solutionService.searchSolutions(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 添加解决方案
     *
     * @param solutionDTO 解决方案数据传输对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "添加解决方案")
    @ResponseBody
    public RestResult<Boolean> addSolution(@RequestBody @Validated(CreateGroup.class) SolutionDTO solutionDTO) {
        Boolean result = solutionService.addSolution(solutionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改解决方案
     *
     * @param solutionDTO 解决方案数据传输对象
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "修改解决方案")
    @ResponseBody
    public RestResult<Boolean> updateSolution(@RequestBody @Validated(UpdateGroup.class) SolutionDTO solutionDTO) {
        Boolean result = solutionService.updateSolution(solutionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除解决方案
     *
     * @param solutionDTO 解决方案数据传输对象
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "删除解决方案")
    @ResponseBody
    public RestResult<Boolean> deleteSolution(@RequestBody @Validated(DeleteGroup.class) SolutionDTO solutionDTO) {
        Boolean result = solutionService.deleteSolution(solutionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
